package cn.whdream.syn;

import java.util.Iterator;
/**
 * 
 * @author black
 *     死锁
 */
public class SynDemo3 {
	
	public static void main(String[] args) throws InterruptedException {
		Object good = new Object();
		Object money = new Object();
		Test t = new Test(good,money);
		Test1 t1 = new Test1(good, money);
		Thread thread = new Thread(t);
		Thread thread2 = new Thread(t1);
		thread.start();
		thread2.start();
	}
	
 static	class Test implements Runnable{
		Object good;
		Object money;
		
		public Test(Object good, Object money) {
			super();
			this.good = good;
			this.money = money;
		}

		@Override
		public void run() {
			while (true) {
				zzz();
			}
		}
		public void zzz(){
			synchronized (good) {
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				synchronized (money) {
					
				}
				System.out.println("一手交钱");
			}
		}
		
	}
	
static	class Test1 implements Runnable{
		Object good;
		Object money;
		
		public Test1(Object good, Object money) {
			super();
			this.good = good;
			this.money = money;
		}

		@Override
		public void run() {
			while (true) {
				zz();
			}
		}
		public void zz() {
			synchronized (money) {
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				synchronized (good) {
					
				}
				System.out.println("一手交货");
			}
		}
		
	}
}

